package pattern.composit;

import java.util.ArrayList;
import java.util.Iterator;

public class Menu extends MenuComponent
{
	ArrayList<MenuComponent> menuComponent;
	String name;
	String description;
	public Menu(String name, String description)
	{
		this.name = name;
		this.description = description;
	}
	@Override
	public void add(MenuComponent menuComponent) throws Exception
	{
		menuComponent.add(menuComponent);
	}
	@Override
	public void remove(MenuComponent menuComponent) throws Exception
	{
		menuComponent.remove(menuComponent);
	}
	@Override
	public MenuComponent getChild(int i) throws Exception
	{
		return menuComponent.get(i);
	}
	@Override
	public String getName() throws Exception
	{
		return name;
	}
	@Override
	public String getDiscription() throws Exception
	{
		return description;
	}
	@Override
	public void print() throws Exception
	{
		System.out.println(name+description);
		Iterator<MenuComponent> iterator = menuComponent.iterator();
		while(iterator.hasNext())
		{
			MenuComponent next = iterator.next();
			next.print();
		}
	}
}
